
import java.util.Hashtable;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author USER
 */
 class HashTable implements WordSet
 { 
     
      private Hashtable<String, Word> table;
        /**
         * Construct the hash table.
         */
        public HashTable( )
        {
      table = new Hashtable<String, Word>();
     
        }

        /**
         * Construct the hash table.
         * @param size the approximate initial size.
         */
  

        /**
         * Insert into the hash table. If the item is
         * already present, do nothing.
         * @param x the item to insert.
         */
        public void add( Word x )
        {
            table.put(x.getWord(), x);
        }

        /**
         * Expand the hash table.
         */
        private void rehash( )
        {
            HashEntry [ ] oldArray = array;

                // Create a new double-sized, empty table
            allocateArray( ( 2 * oldArray.length ) );
            currentSize = 0;

                // Copy table over
            for( int i = 0; i < oldArray.length; i++ )
                if( oldArray[ i ] != null && oldArray[ i ].isActive )
                    get( oldArray[ i ].element );

            return;
        }

        /**
         * Method that performs quadratic probing resolution.
         * @param x the item to search for.
         * @return the position where the search terminates.
         */


        /**
         * Remove from the hash table.
         * @param x the item to remove.
         */
        public void remove( Word x )
        {
           table.remove(x.getWord());
        }

        /**
         * Find an item in the hash table.
         * @param x the item to search for.
         * @return the matching item.
         */
 

        /**
         * Return true if currentPos exists and is active.
         * @param currentPos the result of a call to findPos.
         * @return true if currentPos is active.
         */
        private boolean isActive( int currentPos )
        {
            return array[ currentPos ] != null && array[ currentPos ].isActive;
        }

        /**
         * Make the hash table logically empty.
         */
        public void makeEmpty( )
        {
            currentSize = 0;
            for( int i = 0; i < array.length; i++ )
                array[ i ] = null;
        }

        /**
         * A hash routine for String objects.
         * @param key the String to hash.
         * @param tableSize the size of the hash table.
         * @return the hash value.
         */
 

        private static final int DEFAULT_TABLE_SIZE = 11;

            /** The array of elements. */
        private HashEntry [ ] array;   // The array of elements
        private int currentSize;       // The number of occupied cells

        /**
         * Internal method to allocate array.
         * @param arraySize the size of the array.
         */
        private void allocateArray( int arraySize )
        {
            array = new HashEntry[ arraySize ];
        }
        
        
  

 public Word get(Word x)
        {
/* 1*/   return table.get(x.getWord());
         
        }

    
}
